package com.sky.controller.admin;


import com.sky.result.Result;
//统一结果返回给前端
import io.swagger.annotations.Api;
//标注接口文档，把他转成接口文档
import io.swagger.annotations.ApiOperation;
//写在方法上的接口文档
import lombok.extern.slf4j.Slf4j;
//日志，记录错误信息
import org.springframework.beans.factory.annotation.Autowired;
//依赖注入
import org.springframework.data.redis.core.RedisTemplate;
//用于Rest对象的东西
import org.springframework.web.bind.annotation.PathVariable;
//此注解用于声明路径
import org.springframework.web.bind.annotation.PutMapping;
// 一般用于修改
import org.springframework.web.bind.annotation.RequestMapping;
//提取此类中相同的路径
import org.springframework.web.bind.annotation.RestController;
//类似于component的子类 将对象提供给ioc容器

@RestController("adminShopController")
//表现层
@Slf4j
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
//
public class ShopController {

    public static final String KEY = "SHOP_STATUS";

    //取出ioc容器中的对象
    @Autowired
    private RedisTemplate redisTemplate;


    @PutMapping("/{status}")
    @ApiOperation("设置店铺的营业状态")
    public Result setStatus (@PathVariable Integer status){
        log.info("设置店铺的营业状态为：{}",status == 1 ? "营业中" : "打烊中");

        redisTemplate.opsForValue().set(KEY,status);
        return Result.success(status);

    }

    @PutMapping("/status")
    @ApiOperation("获取店铺的营业状态")
    public Result<Integer> getStatus(){

        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);

        log.info("获取到店铺的营业状态为：{}",status == 1 ? "营业中" : "打烊中");

        return Result.success(status);

    }


    public  Result<Integer> getStatuss(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        return  Result.success(status);

    }



}
